package cn.cmkj.auction.data.http;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by cunguoyao on 2018-05-08.
 */

public class AuctionPrice implements Serializable {

    private String name;
    private BigDecimal price;
    private String time;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public static AuctionPrice parseFromJson(JSONObject json) {
        if (json == null) return null;
        AuctionPrice bean = new AuctionPrice();
        bean.setName(json.optString("name"));
        double price = json.optDouble("now_price", 0);
        bean.setPrice(BigDecimal.valueOf(price));
        bean.setTime(json.optString("create_time"));
        return bean;
    }

    public static List<AuctionPrice> parseJsonArray(JSONArray array) {
        List<AuctionPrice> list = new ArrayList<>();
        if(array != null && array.length() > 0){
            for(int i=0;i<array.length();i++){
                list.add(parseFromJson(array.optJSONObject(i)));
            }
        }
        return list;
    }
}
